<template>
	 <uni-nav-bar :title="title" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
	 <view class="package success">
		<image :src="succeeded" mode=""></image>
		 <view>{{type=='integral'?'兑换成功':'支付成功'}}</view>
	 </view>
	 <view class="bottom">
		 <text @click="redirectTo('order/myStock')">我的存货</text>
		 <text @click="UseNow()" v-if="type=='integral'">立即使用</text>
		 <text @click="redirectTo('order/myOrder')" v-else>查看订单</text>
	 </view>
</template>

<script setup lang="ts">
import { navBack, redirectTo } from '@/utils/navigator';
import { onLoad } from '@dcloudio/uni-app';
import { errorToast, successToast } from '@/utils/prompt';
import { ref } from 'vue';
import { getDriverID } from '@/stores/driverID';
import { succeeded } from '@/utils/Static';
import { toPublish } from '@mqtt';
const user_id = getDriverID();
const type = ref();
const title = ref('');
const integralID = ref('');
const goodsID = ref('');
const repeat = ref(true); //放重复点击
onLoad((pearm) => {
  type.value = pearm.type;
  goodsID.value = pearm.goodsID;
  integralID.value = pearm.id;
  title.value = pearm.type == 'integral' ? '兑换完成' : '支付完成';
});
function UseNow() {
  if (!repeat.value) {
    return;
  }
  repeat.value = false;
  const payload = {
    user_id,
    goods_id: Number(goodsID.value),
    goods_nums: 1,
    dispatch_id: 4,
  };
  toPublish('store/addHexiaoOrderByGoodsId', payload, (obj: any) => {
    const { code, msg, data } = obj;
    console.log(JSON.stringify(data));
    if (code === 1) {
      successToast(msg);
      setTimeout(() => {
        redirectTo('groupBenefits/deliveryDetail?id=' + data.order_id + '&type=virtual');
      }, 1000);
    } else {
      repeat.value = true;
      errorToast(msg);
    }
  });
}
</script>

<style scoped lang="less">
.success {
  height: 340rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  image {
    width: 168rpx;
    height: 168rpx;
  }
  view {
    font-size: 24rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #666666;
  }
}
.bottom {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin-top: 20rpx;
  text:nth-of-type(1) {
    width: 236rpx;
    height: 80rpx;
    border-radius: 5px;
    border: 1px solid #1b91ff;
    font-size: 36rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #1b91ff;
    text-align: center;
    line-height: 80rpx;
  }
  text:nth-of-type(2) {
    width: 266rpx;
    height: 80rpx;
    background: #1b91ff;
    border-radius: 5px;
    font-size: 36rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #ffffff;
    text-align: center;
    line-height: 80rpx;
  }
}
</style>